<?php
class ControlMoney
{
	public function findUserMoneyByUserID($userid)
	{
		$sql = "SELECT * FROM usermoney WHERE (userid ='$userid')";
		if(!($result = mysql_query($sql))) die(mysql_error());
		return mysql_fetch_array($result);
	}
	
	public function setUserMoneyByUserIDAndAmount($userid, $money)
	{
		$sql = "UPDATE usermoney SET Money='$money' WHERE UserID='$userid'";
		mysql_query($sql);
	}
	
	public function addMainUserMoney($userid, $amount)
	{
		$row = $this->findUserMoneyByUserID($userid);
		$money = floatval($row['Money']) + $amount;
		$this->setUserMoneyByUserIDAndAmount($userid, $money);
	}

	public function subMainUserMoney($userid, $amount)
	{
		$row = $this->findUserMoneyByUserID($userid);
		$money = floatval($row['Money']) - $amount;
		$this->setUserMoneyByUserIDAndAmount($userid, $money);
	}
}
?>